[ Intro ]   [ Lesson1 ]   [ Lesson2 ]   [ Lesson3 ]   [ Lesson4 ]   [ Lesson5 ]   [ Lesson6 ]   [ Lesson7 ]   [ Lesson8 ]

 


Basic damage animations

Now we shall work with the simple damage animations of a TA unit, such as smoking and death explosions. Load example2.bos into Scriptor, then read on.


SmokeUnit.h

example

#define SMOKEPIECE1 body
#include "SmokeUnit.h"

To eliminate work, instead of having to manually add in code for unit smoke and setting up what to smoke when, we can use a .h include, which has it's own ('pre-processored') code to work out the relevant function for our script. This time we'll use Smokeunit.h, and as you can see, the line begins with #. This symbol is used for almost all the pre-processor code, such as to define or include other things, and to indicate the code in the .h which works out what Scriptor needs to output. You can find and edit the actual SmokeUnit.h file in the scriptor\includes directory.

If you open Smokeunit.h in any text editor, such as Notepad or Scriptor, you'll see the comment // Figure out how many smoking pieces are defined. Then look back at the line above where we included Smokeunit.h. We have use some pre-processor code to define the name of the first smokepiece. Now, the pre-processor code in the include checks how many pieces we've defined, with that #ifdef. We don't need to understand all this, simply that there's a limit to the number of smokepieces we can use this include to autoscript for. In this case it's 4 (much later I shall explain how to increase this limit, or to do the pre-processor work yourself for a complex unit), and we've only used 1 smokepiece.

example

Create()
{
var1 = 1;
start-script SmokeUnit();
}

Lastly we need the script to constantly check for any damage, and to emit smoke from the smokepieces depending on the level of damage. To do this we add a line to Create() function, start-script SmokeUnit();. As it says, this starts the function SmokeUnit(), which is from the Smokeunit.h include and will perform this looping check. Now if we build our TA unit and damage it, it will smoke like normal.


Killed(severity, corpsetype)

example

Killed(severity, corpsetype)
{
if( severity <= 25 )
{
corpsetype = 1;
explode body type BITMAPONLY | BITMAP1;
return (0);
}
if( severity <= 50 )
{
corpsetype = 2;
explode body type FALL | BITMAP1;
return (0);
}
if( severity <= 99 )
{
corpsetype = 3;
explode body type FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP1;
return (0);
}
corpsetype = 3;
explode body type FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP1;
}

The other main damage animation is the death explosions. These are caused when the unit is killed, and can differ depending on the severity of the final blow. We can also decide what type of corpse to convert to, with weak damage leaving a corpse model resembling the normal unit, and high damage leaving a few smoking rocks, or simply disintegrate the whole thing, leaving nothing but debris and smoke. The severity is passed to us from the TA engine, and we return the corpse type to use. The specific values it checks against: 25; 50; 99; and the corpsetype = x; lines are usually not altered, only the type of explosion.

The value of the severity is checked with a simple if() statement, and the encapsulated code will be run if the condition is fulfilled. Note that a variable is given a value with one =, but it's value is checked with two expression terms (e.g. == or <=). If the severity is very low, this would satisfy all the if() statements, but we only want one lot of animations. Thus we return (0);, which ends the function here, instead of carrying on to the main } this function is contained within. The value 0 is used as this is how TA works with Killed() functions. More about return statements later.

more info

if () -functions

Now our TA unit will not just disappear when killed, but perform an animated death, with the specific explosions and corpse being dependant on the damage of the final hit. If this is the case, you can either continue to Lesson3, or read the next little snippet of info, explaining...


More about includes

In this case we only needed to include Smokeunit.h, and if you look at it again you might find #include "SFXtype.h" and #include "EXPtype.h". These define many special effects, such as smoke and explosion animations. All you need to know is that if you want to use these effects and have not included Smokeunit.h, you will have to specify you want to include these in you script. Again the code goes at the top, between static-var and functions.

Congratulations and everything, but hey... let us make haste onwards Lesson 3.


© Proud like a god (and a little Storm)